<?php 
$css = ['/assets/jedate/skin/jedate.css'];
$this->load->view('admin/layout/head', array('title'=>"订单管理",'nav'=>'order','css'=>$css), FALSE);
?>

<div id="container">
	<form class="form-inline" id="search-form" method="GET" action="">
	  <div class="form-group">
	  	<select name="type" id="type_slt" class="form-control">
	  		<option value=""><?= $this->lang->line('order_type'); ?></option>
	  		<option value="0"><?= $this->lang->line('order_online')  ?></option>
	  		<option value="1"><?= $this->lang->line('order_offline')  ?></option>
	  	</select>
	  	<select name="status" id="type_slt" class="form-control">
	  		<option value=""><?= $this->lang->line('status'); ?></option>
	  		<?php $status = CONFIG('basic.order_status');?>
	  		<?php foreach ($status as $k=>$s):?>
	  		<option value="<?php echo $k ?>" 
	  		<?php if (strval($k) === $this->input->get('status')): ?>
	  			selected
	  		<?php endif ?>><?php echo $s[$this->session->admin_language] ?></option>
	  		<?php endforeach; ?>
	  	</select>
	  </div>
	  <div class="form-group">
	  	<input type="text" name="start_date" class="form-control date-picker" value="<?= $this->input->get('start_date') ?>" placeholder="<?= $this->lang->line('start date') ?>">
	  	<input type="text" name="end_date" class="form-control date-picker" value="<?= $this->input->get('end_date') ?>" placeholder="<?= $this->lang->line('end date') ?>">
	  </div>

	  <div class="form-group">
	  	<input type="text" name="order_id" class="form-control" value="<?= $this->input->get('order_id') ?>" placeholder="<?= $this->lang->line('order no') ?>">
	  </div>
	  <div class="form-group">
	  	<input type="text" name="phone" class="form-control" value="<?= $this->input->get('phone') ?>" placeholder="<?= $this->lang->line('user phone') ?>">
	  </div>

	  <button class="btn btn-info search-btn"><?= $this->lang->line('search') ?></button>
	</form>
	<div class="table-container mt-10">
		<table class="table table-bordered table-striped table-hover scroll-table">
			<thead >
				<tr>
					<th class="text-center">id</th>
					<th class="text-center"><?= $this->lang->line('order no') ?></th>
					<th class="text-center"><?= $this->lang->line('order_type') ?></th>
					<!-- <th class="text-center"><?= $this->lang->line('user') ?></th> -->
					<th class="text-center"><?= $this->lang->line('total fee') ?></th>
					<th class="text-center"><?= $this->lang->line('cut fee') ?></th>
					<th class="text-center"><?= $this->lang->line('express fee') ?></th>
					<th class="text-center"><?= $this->lang->line('status') ?></th>
					<th class="text-center"><?= $this->lang->line('time') ?></th>	
					<th class="text-center"><?= $this->lang->line('actions'); ?></th>
				</tr>
			</thead>
			<tbody class="text-center">
				<?php foreach ($page as $key => $value): ?>
					<tr id="<?= $value['id'] ?>">
						<td><?= $value['id'] ?></td>
						<td><?= $value['order_id'] ?></td>
						<td><?php echo $value['type']?'<span style="color:#f60">'.$this->lang->line("order_offline").'</span>':$this->lang->line('order_online') ?></td>
						
						<td><?= $value['total'] ?></td>
						<td><?= $value['cut_fee'] ?></td>
						<td>
							<?= $value['shipping_fee'] ?>
							<?php if($value['shipping_date'] == date('Y-m-d')): ?>
							[今天 <?php echo $value['shipping_time'] ?>]
							<?php endif; ?>
						</td>
						<td>
							<?= get_order_status($value['status']); ?>
							<?php if($value['have_refund']>0): ?>
							<span style="color: #f60">[退]</span>
							<?php endif; ?>
						</td>
						<td><?= $value['create_time'] ?></td>
						<td>
							<?php if ($value['status'] == 0): ?>
								<a href="#" class="cancel"><?= $this->lang->line('cancel order') ?></a>
							<?php endif ?>
						
							<a href="/admin/order/detail/<?= $value['id'] ?>"><?= $this->lang->line('detail') ?></a>
							<?php if ($value['isdel'] == 0): ?>
								<a href="#" class="del" data-id="<?= $value['id'] ?>">删除</a>	
							<?php endif ?>
							
						</td>
					</tr>
				<?php endforeach ?>
			</tbody>
			<?php if ($page->last_page>1): ?>
				<tfoot>
					<td colspan="9" style="text-align:right">
						<?php echo $page->render() ?>
					</td>
				</tfoot>
			<?php endif ?>
		</table>
	</div>
</div>


<?php 
$js = ['/assets/jedate/jedate.min.js'];
$this->load->view('admin/layout/footer',['js'=>$js]);
?>

<script type="text/javascript">
	$(function(){
		datepicker('.date-picker','<?php echo $this->session->admin_language ?>');
		$('.cancel').on('click', function () {
			var id = $(this).parents('tr').attr('id');
			Toast.loading();
			$.ajax({
				url: '/admin/order/cancel/'+id,
				type: 'get',
				success: function (json) {
					Toast.destory();
					Toast.success('<?= $this->lang->line('success') ?>', function () {
						window.location.reload();
					});
				},
				error: function (json) {
					Toast.error(json.error);
				}
			})
		});

		var hash = window.location.hash;
		if(hash){
			$(hash).css('background-color','#ccc');
		}

		$('.del').on('click', function () {
			var id = $(this).attr('data-id');
			Toast.loading();
			$.ajax({
				url: '/admin/order/delete/'+id,
				type: 'get',
				success: function (json) {
					Toast.destory();
					Toast.success('<?= $this->lang->line('success') ?>', function () {
						window.location.reload();
					});
				},
				error: function (json) {
					Toast.error(json.error);
				}
			})
		})
	})
</script>















